package com.song.shop.test;

import com.alibaba.fastjson.JSON;
import com.song.shop.entity.Shop;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.*;
import java.util.concurrent.*;

/**
 * @author Song Yinghui
 * @date 2019/8/8
 * @Version 1.0
 */
public class test13 {

    private RedisTemplate redisTemplate ;

    private MongoTemplate mongoTemplate ;

    public void test(){
        for (int l = 0;l < 9000; l++) {
            OUTER:
            for (int j = 0; j < 1000; j++) {
                for (int k = 0; k < 100; k++) {
                    if (k == 20) {
                        break OUTER;
                    }
                }
            }
        }
    }

    public static void main(String[] args) {

        HashSet<String> set = new HashSet<>();
        set.add("1231");
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        list.add("11");
        list.get(1);

        List<String> list1 = new ArrayList<>();
        list1.add("12");

        Shop shop = new Shop();
        shop.setShopName("测试");
        System.out.println(Optional.ofNullable(shop.getShopName()).map(item -> item+"123").orElse(""));

        ConcurrentHashMap<String,String> hashMap = new ConcurrentHashMap<>();
        hashMap.put("","");
        HashMap<String,String> hashMap1 = new HashMap<>();
        hashMap1.put("","");
    }

    public static void test2() {
        String s2 = "1";
        String s1 = new String("1");
        String intern = s1.intern();

        System.out.println(s1 == s2);
        System.out.println(intern == s1);
        System.out.println(intern == s2);

        BlockingQueue blockingQueue = new ArrayBlockingQueue(10,false);

        List<Integer> list = new ArrayList<>();
        for (int i =0 ; i<100; i++){
            list.add(i);
        }
        int count = 0 ;
        for (int j = 0; j< list.size(); j++){
            count++;
            if (list.get(j) % 2 == 0){
                list.remove(j);
            }
        }
        System.out.println(count);
        System.out.println(JSON.toJSONString(list));
    }

    public static void test1() {
        String cityCode = "370";

        System.out.println(cityCode.endsWith("0"));
        System.out.println("000".endsWith("0"));
        String s1 = StringUtils.leftPad(cityCode, 4, "0");
        System.out.println(cityCode+"---"+s1);
        System.out.println(StringUtils.substring(s1, 0, s1.length() - 1));
        System.out.println("0370".substring(0, 3));

        System.out.println(StringUtils.lastIndexOf(s1, "0"));

        Shop shop = new Shop();
        shop.setId("1");
        shop.setShopName("测试");
        TestShop testShop = new TestShop();
        testShop.setTestName("外层名称");
        testShop.setShop(shop);

        String s = JSON.toJSONString(testShop);
        System.out.println(s);

        TestShop testShop1 = JSON.parseObject(s, TestShop.class);
        System.out.println(JSON.toJSONString(testShop1));
    }

}
